﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using coliseu.BussinessLayer;

namespace coliseu.Views.Rotinas_Diarias
{
    public partial class FrmCadRotina : Form
    {
        private RotinaBL rBL;
        private rotina r;

        public FrmCadRotina(RotinaBL rBL)
        {
            InitializeComponent();
            this.rBL = rBL;
            rotinaBindingSource.AddNew();
        }

        public FrmCadRotina(rotina r, RotinaBL rBL)
        {
            InitializeComponent();
            this.rBL = rBL;
            this.r = r;
            rotinaBindingSource.DataSource = r;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ValidateChildren();
            Validate();

            ((rotina)rotinaBindingSource.Current).data = dataDateTimePicker.Value.Date;

            rotinaBindingSource.EndEdit();

            if (r == null)
                rBL.salvar((rotina)rotinaBindingSource.Current, "insert");
            else
                rBL.salvar((rotina)rotinaBindingSource.Current, "edit");

            MessageBox.Show("Salvo com sucesso", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Close();
        }

        private void FrmCadRotina_Load(object sender, EventArgs e)
        {

        }
    }
}
